<template>
    <div>
      <!--导航栏-->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>

      <el-card>
      <el-row :gutter="20">
        <el-col :span="7">
          <!--输入时可出现清空图标x-->
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrdersList">
            <template #append>
              <el-button icon="el-icon-search" @click="getOrdersList"></el-button>
            </template>
          </el-input>
        </el-col>
      </el-row>

      <el-table border stripe :data="ordersList">
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="150px"></el-table-column>
        <el-table-column label="是否付款" width="150px">
          <template #default="scope">
            <el-tag v-if="scope.row.pay_status==='1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" width="150px">
          <template #default="scope">
            {{scope.row.is_send=scope.row.is_send==='1'?'已发货':'未发货'}}
          </template>
        </el-table-column>
        <el-table-column label="下单时间" width="200px">
          <template #default="scope">
            {{scope.row.create_time|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template #default="">
            <el-button size="mini" class="el-icon-edit" type="primary" @click="editOrderDialogVisible=true"></el-button>
            <el-button size="mini" class="el-icon-location" type="success" @click="showProgVisible=true"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!--分页器-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

      <!--编辑订单对话框-->
      <el-dialog
        title="修改地址"
        :visible.sync="editOrderDialogVisible"
        width="50%"
      >
        <el-form label-width="100px" :model="editOrderForm">
          <el-form-item label="省市区/县">
            <el-cascader
              v-model="editOrderForm.addr"
              :options="cityData"
              clearable
            >
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" >
            <el-input v-model="editOrderForm.addr_detail"></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
        <span class="dialog-footer">
    <el-button @click="editOrderDialogVisible = false">取 消</el-button>
    <el-button type="primary">确 定</el-button>
  </span>
        </template>
      </el-dialog>

      <!--物流进度对话框-->
      <el-dialog
        title="物流进度"
        :visible.sync="showProgVisible"
        width="50%"
        @open="getProg"
      >
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in progInfo"
            :key="index"
            :timestamp="item.time">
            {{item.context}}
          </el-timeline-item>
        </el-timeline>
        <template #footer>
        <span class="dialog-footer">
    <el-button @click="showProgVisible = false">取 消</el-button>
    <el-button type="primary">确 定</el-button>
  </span>
        </template>
      </el-dialog>
    </div>

</template>

<script>
import citydata from '../../../public/citydata'
export default {
  name: 'Orders',
  data () {
    return {
      cityData: citydata,
      queryInfo: {
        query: '', // 关键字
        pagenum: 1, // 页码
        pagesize: 10 // 条数
      },
      ordersList: [],
      total: 0, // 订单总数
      editOrderDialogVisible: false,
      editOrderForm: {
        addr: [],
        addr_detail: ''
      },
      showProgVisible: false,
      progInfo: []
    }
  },
  created () {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList () {
      const { data } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (data.meta.status !== 200) return this.$message.error('获取订单列表失败')
      // 获取成功
      this.ordersList = data.data.goods
      this.total = data.data.total
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    handleCurrentChange (current) {
      this.queryInfo.pagenum = current
      this.getOrdersList()
    },
    async getProg () {
      const { data: res } = await this.$http.get('http://localhost:8080/info.json')
      this.progInfo = res.data
    }
  }
}
</script>

<style scoped>

</style>
